package com.ciwong.epaper.modules.me.ui;

import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.util.EConstants;
import com.ciwong.epaper.util.IntentFlag;
import com.ciwong.libs.utils.CWSys;
import com.ciwong.mobilelib.ui.BaseActivity;

/**
 * 跟读设置
 *
 * @author sugy
 * @version ciwong v.1.0 2015/11/10 18:43
 * @since ciwong v.1.0
 */
public class ReadSettingActivity extends BaseActivity
{
    private ImageView ivPlayBack, ivAssess;

    private View readTipView;

    private boolean isDialog = false;

    private Button btnClose;

    private ImageView iv_setting_listen_speak;

    private View.OnClickListener onClickListener = new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            v.setSelected(!v.isSelected());
            int i = v.getId();
            if (i == R.id.iv_setting_assess)
            {
                CWSys.setSharedBoolean(
                        EConstants.SHARE_KEY_IS_ASSESS
                                + getUserInfoBase().getUserId(),
                        v.isSelected());

            } else if (i == R.id.iv_setting_listen_speak) {

                CWSys.setSharedBoolean(
                        EConstants.SHARE_KEY_IS_PLAY_STEM_AUDIO
                                + getUserInfoBase().getUserId(),
                        v.isSelected());

            } else if (i == R.id.btn_close_setting) {
                finish();

            }
        }
    };

    @Override
    protected void preCreate()
    {
        super.preCreate();
        isDialog = getIntent().getBooleanExtra(IntentFlag.INTENT_FLAG_ACTION,
                false);
        if (!isDialog)
        {
            setTheme(R.style.AppTheme);
        }
    }

    @Override
    public void onBackPressed() {
        setResult(RESULT_OK);
        finish();
    }

    @Override
    protected int setView()
    {
        return R.layout.activity_read_setting;
    }

    @Override
    protected void findViews()
    {
//        readTipView = findViewById(R.id.layout_setting_read_tip);
//        ivPlayBack = (ImageView) findViewById(R.id.iv_setting_play_back);
        ivAssess = (ImageView) findViewById(R.id.iv_setting_assess);
        btnClose = (Button) findViewById(R.id.btn_close_setting);

        iv_setting_listen_speak = (ImageView) findViewById(R.id.iv_setting_listen_speak);

    }

    @Override
    protected void initEvent()
    {
        readTipView.setOnClickListener(onClickListener);
        ivPlayBack.setOnClickListener(onClickListener);
        ivAssess.setOnClickListener(onClickListener);
        btnClose.setOnClickListener(onClickListener);
        iv_setting_listen_speak.setOnClickListener(onClickListener);
    }

    @Override
    protected void init()
    {
        if (isDialog)
        {
            getWindow().setBackgroundDrawableResource(
                    R.drawable.shape_repeat_read_setting_bg);
            hideTitleBar();
            btnClose.setVisibility(View.VISIBLE);
            readTipView.setVisibility(View.GONE);
        }
        else
        {
            setTitleText(R.string.read_setting);
        }
        //设置页面 是否回放录音
        boolean isPlayBack = CWSys
                .getSharedBoolean(EConstants.SHARE_KEY_PLAY_BACK_AUDIO
                        + getUserInfoBase().getUserId(), false);
        ivPlayBack.setSelected(isPlayBack);

        boolean isAssess = CWSys.getSharedBoolean(
                EConstants.SHARE_KEY_IS_ASSESS + getUserInfoBase().getUserId(),
                false);
        ivAssess.setSelected(isAssess);

        boolean isPlayStemAudio=CWSys.getSharedBoolean(EConstants.SHARE_KEY_IS_PLAY_STEM_AUDIO + getUserInfoBase().getUserId(), true);

        iv_setting_listen_speak.setSelected(isPlayStemAudio);
    }

    @Override
    protected void loadData()
    {

    }
}
